package co.fitstart.admin.job;

import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import co.fitstart.admin.service.CourseRoundService;

/**
 * 
 * @author dan
 *
 */
@Component("sessionTaskJob")
public class CourseRoundLastJob {
    
    private static final Logger logger = LoggerFactory.getLogger(CourseRoundLastJob.class);
    
    @Autowired
    private CourseRoundService courseRoundService;
    
    /**
     *  更新课程是否为最后一节课的job
     */
    @Scheduled(cron = "0 0 4 * * *")
    public void lastCourse() {
        
        Date now = new Date();
        logger.info("start update lastcourse at {}", now);
        
        int nullLastCourse = courseRoundService.countLastCourseNull();
        logger.info("get nullLastCourse count {}", nullLastCourse);
        
        if(nullLastCourse > 0) {
            courseRoundService.updateLastCourse();
        }
        
    }
}
